#include "owner.h"
#include "ui_owner.h"
#include "entity/ownerentity.h"
#include "dbmanager.h"

Owner::Owner(QWidget *parent) :
    QWidget(parent), ui(new Ui::Owner)
{
    ui->setupUi(this);
    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
    connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearClicked()));
    connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
}

Owner::~Owner()
{
    delete ui;
}

void Owner::okClicked()
{
    OwnerEntity * owner = new OwnerEntity();
    owner->setOwnerName(ui->ownerNameText->text());
    owner->setOwnerRegNo(ui->ownerRegNoText->text());
    owner->setPhone1(ui->ownerPhone1Text->text());
    owner->setPhone2(ui->ownerPhone2Text->text());
    owner->setAddress1(ui->ownerAddress1Text->text());
    owner->setCity1(ui->ownerCity1Text->text());
    owner->setAddress2(ui->ownerAddress2Text->text());
    owner->setCity2(ui->ownerCity2Text->text());
    owner->setEmail(ui->ownerEmailText->text());
    owner->setFax(ui->ownerFaxText->text());
    owner->setDeleted(0);

    DBManager * dbm = DBManager::getGlobal();
    dbm->insertOwner(owner);

    delete owner;
}

void Owner::clearClicked()
{

}

void Owner::cancelClicked()
{

}
